package com.dora.rabbitmq.service.impl;

import com.dora.rabbitmq.po.Mail;
import com.dora.rabbitmq.service.Publisher;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service("publisher")
public class PublisherImpl implements Publisher {

	@Autowired
	RabbitTemplate rabbitTemplate;

	@Override
	public void publishMail(Mail mail) {
		rabbitTemplate.convertAndSend("fanout", "", mail);
	}

	@Override
	public void sendDirectMail(Mail mail, String routingKey) {
		rabbitTemplate.convertAndSend("direct", routingKey, mail);
	}

	@Override
	public void sendTopicMail(Mail mail, String routingKey) {
		rabbitTemplate.convertAndSend("mytopic", routingKey, mail);
	}

	
	
}
